package com.example.tool.activtiy;

import android.widget.TextView;

import com.example.tool.R;
import com.example.tool.activtiy.base.BaseActivity;
import com.example.tool.mvp.CommonPresent;
import com.example.tool.util.DataRequest;
import com.example.tool.util.DebugLog;
import com.example.tool.widget.BarRoundChartView;
import com.example.tool.widget.BarRoundWeekView;
import com.example.tool.widget.mpview.CountLineChart;
import com.example.tool.widget.mpview.MPChartHelper;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

import static com.example.tool.util.DebugLog.FILE_TOOL;

/**
 * 描述: 自定义view
 *
 * @author: liangkun
 * @date: 2019/10/14 11:27
 */
public class CustomViewActivity extends BaseActivity<CommonPresent> {
    @BindView(R.id.bar_chart)
    protected BarRoundChartView roundChartView;
    @BindView(R.id.bar_week)
    protected BarRoundWeekView barRoundWeekView;
    @BindView(R.id.tv_title)
    protected TextView tvTitle;
    @BindView(R.id.line_chart)
    protected CountLineChart countLineChart;

    @Override
    protected int getLayoutId() {
        return R.layout.custom_view;
    }

    @Override
    protected void initView() {
        tvTitle.setText("自定义View");
        roundChartView.setListener((number, x, y) -> DebugLog.d(FILE_TOOL + " number " + number));
        roundChartView.setList(getList());
        barRoundWeekView.setListener(new BarRoundWeekView.getNumberListener() {
            @Override
            public void getNumber(int number, float x, float y) {

            }
        });

    }

    private List<Float> getList() {
        List<Float> floatList = new ArrayList<>();
        for (int i = 0; i < 12; i++) {
            floatList.add((float) DataRequest.getRandom(120));
        }
        return floatList;
    }

    private List<Float> getList2() {
        List<Float> floatList = new ArrayList<>();
        for (int i = 0; i < 21; i++) {
            floatList.add((float) DataRequest.getRandom(120));
        }
        return floatList;
    }

    @Override
    protected void initData() {
        barRoundWeekView.setList(getList2(), 4);
        //曲线图
        List<String> xAxisValue = getAxisValue();
        MPChartHelper.setLineChart(countLineChart, xAxisValue, getList2(), "测试demo", CustomViewActivity.this);
    }

    private List<String> getAxisValue() {
        List<String> stringList = new ArrayList<>();
        for (int i = 0; i < 21; i++) {
            stringList.add(i + "");
        }
        return stringList;
    }

    @Override
    protected void initEvent() {

    }

    @Override
    protected CommonPresent createPresenter() {
        return null;
    }
}
